﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.Security;
using System.Runtime.InteropServices;


namespace iResume
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text=DBManager.countresume();
            Label4.Text = DBManager.countrecruiter();
            string username = (string)(Session["username"]);


            if (username == null)
            {
                navip.Visible = true;


            }


            if (username == null)
            {
                Div1.Visible = true;
            }


            
            if (username == null)
            {
                dialogConfirmContainer.Visible = false;
            }

            if (!IsPostBack)
            {
                string usertype = (string)(Session["usertype"]);
                
              //  datelbl.Text = DateTime.Now.ToShortDateString();
                //timelbl.Text = DateTime.Now.ToShortTimeString();

                if (usertype == "Job Seeker")
                {
                    namelbl.Text = "Welcome " + "<b>" + username + "</b>" + " " + "(" + usertype + ")" + " ";
                    Panel4.Visible = true;

                }

                if (usertype == "Recruiter")
                {
                    namelbl.Text = "Welcome " + username+ " " + "(" + usertype + ")" + " ";
                    Panel4.Visible = true;
                }

                if (usertype == "Administrator")
                {

                    Panel4.Visible = true;
                }
            }

                
                DisableBufferingOnPage();

                FormsAuthentication.SignOut();


        }
        protected void DisableBufferingOnPage()
        {
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            // set expiry date in the past
            Response.Expires = -1;
            Response.CacheControl = "no-cache";
            Response.Cache.SetNoStore();
            Response.AppendHeader("Pragma", "no-cache");
            Response.AppendHeader("Cache-Control", "no-cache");
            Response.CacheControl = "no-cache";
            Response.Expires = -1;
            Response.ExpiresAbsolute = new DateTime(1900, 1, 1);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }

        protected void delebtn_Click(object sender, EventArgs e)
        {
            string usertype = (string)(Session["usertype"]);
            string username = (string)(Session["username"]);

            if (usertype == "Recruiter")
            {
                DBManager.deleteRecruiter(username);
                Session["usertype"] = "";
                FormsAuthentication.SignOut();
                Response.Redirect("loginpage.aspx");

            }


            if (usertype == "Job Seeker")
            {
                DBManager.deleteJobseeker(username);
                Session["usertype"] = "";
                FormsAuthentication.SignOut();
                Response.Redirect("loginpage.aspx");
            }

            if (usertype == "Administrator")
            {
                DBManager.deleteAdmin(username);
                Session["usertype"] = "";
                FormsAuthentication.SignOut();
                Response.Redirect("loginpage.aspx");
            }
        }



        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("loginpage.aspx");
        }

        protected void logout_Click1(object sender, EventArgs e)
        {
    
            Session["usertype"] = "";
            Session["username"] = "";
            Session.Clear();
            FormsAuthentication.SignOut(); 
            Response.Redirect("loginpage.aspx");
            
        }

        protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
        {
            
            string usertype = (string)(Session["usertype"]);
            string username = (string)(Session["username"]);

            if (usertype == "Recruiter")
            {
                
                Response.Redirect("recruiterView.aspx");

            }


            if (usertype == "Job Seeker")
            {
                
                Response.Redirect("Loginjobseeker.aspx");
            }

            if (usertype == "Administrator")
            {
                Response.Redirect("LoginAdmin.aspx");
            }

            if (usertype == null)
            {
                Response.Redirect("loginpage.aspx");
            }
        

        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {

        }

        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {

        }

        protected void ImageButton4_Click1(object sender, ImageClickEventArgs e)
        {

        }

    
    }
}
